<template>
    <div class="suggest-header">
        <div class="city-wrapper">
            <div class="city-content border-right-1px">
                <div class="city-select">
                    <span class="text">武汉</span>
                    <span class="icon">
                    </span>

                </div>
            </div>
        </div>
        <div class="address-wrapper">
            <input type="text" :placeholder="upordown" ref="upcars" class="address-input" v-model="suggestInputValue">
        </div>
        <div class="cancel-wrapper">
            <span class="text border-left-1px" @click="back_home">取消</span>
        </div>
    </div>
</template>
<script>
import { mapMutations, mapGetters } from 'vuex'
import Icon from 'vue-awesome/components/Icon'
export default {
    data () {
      return {
        suggestInputValue: '',
        upordown: '',
        searchOption: {
          city: '武汉',
          citylimit: false,
        }
      }
    },
    computed: {
      ...mapGetters([
        'autocompleteList',
        'showChangeNav'
      ])
    },
    watch: {
      suggestInputValue (newVal, odlVal) {
        const _this = this
        if(newVal != odlVal) {
            AMap.plugin('AMap.Autocomplete', function () {
                var autocomplete = new AMap.Autocomplete({})
                autocomplete.search(newVal, function (status, result) {
                    _this.setAutocompleteList(result.tips)
                })
            })
        }
      }
    },
    mounted () {
        this.curfoucs()
    },
    methods: {
        curfoucs () {
            if(localStorage.getItem('parmastype') === 'ups') {
              this.upordown = '请输入上车地点'
            }
            if (localStorage.getItem('parmastype') === 'downs') {
              this.upordown = '请输入下车地点'
            }
            this.$refs.upcars.focus()
        },
        back_home () {
          if(localStorage.getItem('parmastype') == 2 || localStorage.getItem('parmastype') == 3) {
            this.$router.push({path: '/surePrice'})
          }else{
            this.$router.push({path: '/index'})
          }
        },
        // 搜索的输入框 触发的事件
        onSearchResultStart(pois) {
            let locationName = pois[0].name
            if (this.showSearchBox === true) {
                localStorage.setItem('lat1',pois[0].lat)
                localStorage.setItem('lng1',pois[0].lng)
                this.setSearchBoxInfo(locationName)
                this.setShowSearchBox(false)
                this.getDrinkeMap()
            } else {
                this.setDestination(locationName)
                this.getDrinkeMap()
                this.setShowEnd(false)
            }
            let latSum = 0
            let lngSum = 0
            if (pois.length > 0) {
                pois.forEach(poi => {
                    let {lng, lat} = poi
                    lngSum += lng
                    latSum += lat
                    this.markers = []
                    this.markers.push([poi.lng, poi.lat])
                })
                let center = {
                    lng: lngSum / pois.length,
                    lat: latSum / pois.length
                }
                this.mapCenter = [center.lng, center.lat]
                let sc = center.lat + ':' + center.lng
                console.log(sc)
                this.setStartCoor(sc)
            }
        },
        ...mapMutations({
            setAutocompleteList: 'SET_AUTOCOMPLETELIST',
        })
    },
    components: {
        Icon
    }
}
</script>
<style scoped>
.el-vue-search-box-container {
    height: 35px;
    line-height: 35px;
    box-shadow: none;
    border:none;
}
.suggest-header {
    position: relative;
    z-index: 10;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    height: 44px;
    white-space: nowrap;
    background: #fff;
    box-shadow: 0 2px 3px rgba(0, 0, 0, .12);
}

.suggest-header .city-wrapper {
    padding: 13px 0;
    width:15vw;
    float: left;
}

.suggest-header .city-wrapper .city-content {
    height: 18px;
}

.border-bottom-1px,
.border-left-1px,
.border-right-1px,
.border-top-1px {
    position: relative;
}

.suggest-header .city-wrapper .city-content .city-select {
    line-height: 18px;
    padding: 0 16px;
    font-size: 0;
}

.suggest-header .city-wrapper .city-content .city-select .text {
    margin-right: 4px;
}

.suggest-header .city-wrapper .city-content .city-select .text {
    display: inline-block;
    vertical-align: top;
    color: #666;
    font-size: 14px;
}

.suggest-header .address-wrapper {
    padding: 5px 10px;
    width: 65vw;
    float: left;
}

.suggest-header .address-wrapper .address-input {
    height: 14px;
    margin-top: -5px;
    padding: 15px 0;
    font-size: 14px;
    width:100%;
}

input {
    outline: 0;
    border: 0;
}

.suggest-header .address-wrapper .clear {
    position: absolute;
    right: 0;
    top: 14px;
}
.suggest-header .cancel-wrapper {
    float: left;
    width: 20vw;
    text-align: center;
}
.suggest-header .cancel-wrapper .text {
    display: block;
    margin-top: 15px;
    color: #999;
    font-size: 14px;
    text-align: center;
}

.border-bottom-1px,
.border-left-1px,
.border-right-1px,
.border-top-1px {
    //position: relative;
}

.border-left-1px:before {
    border-left: 1px solid #f5f5f5;
    top: 0;
    left: 0;
    height: 100%;
}

.border-bottom-1px:after,
.border-bottom-1px:before,
.border-left-1px:after,
.border-left-1px:before,
.border-right-1px:after,
.border-right-1px:before,
.border-top-1px:after,
.border-top-1px:before {
    content: "";
    display: block;
    position: absolute;
    transform-origin: 0 0;
}
.suggest-header .city-wrapper .city-content .city-input-wrapper {
    width: 143px;
    height: 18px;
    padding: 0 10px;
}
.suggest-header .city-wrapper .city-content .city-input-wrapper .city-input {
    display: table-cell;
    width: 100%;
    height: 14px;
    margin-top: -13px;
    padding: 15px 0;
    vertical-align: middle;
    font-size: 14px;
}
</style>
